<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>抽奖码及中奖情况</title>
    <include file="Public:easyui_res"/>
    <script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
</head>
<body>
<div id="tb" style="padding:5px;height:auto;">
    <div style="margin: 10px 0 10px 10px">
        <!-- form表单 指定id和name之后会自动带到服务器 -->
        <form name="searchform" method="get" action="" id="searchform" style="height:20px;margin-bottom: 20px">
            <label>获奖时间</label>
            <input class="easyui-datebox" id="bt"  name="bt" style="height: 32px;"  /> 到 <input class="easyui-datebox" id="et"  name="et"  style="height: 32px;"  />
            <label for="draw_code">抽奖码：</label>
            <input class="easyui-textbox"  type="text" id="draw_code" name="draw_code" data-options="prompt:'输入抽奖码'" style="height: 32px;">
            <a href="javascript:void(0);" id="submit_search" class="easyui-linkbutton" iconCls="icon-search" style="width:60px;height:32px">查询</a>
        </form>
    </div>
</div>
<table id="dg" style="width:100%; " title="查询结果"
       data-options="rownumbers:false,
			singleSelect:true,
			pagination:true,
			ctrlSelect:true,
			fitColumns:true,
			loadMsg:'正在加载,请等待....',
			url:'__URL__/getWinningList',
			method:'post',
			toolbar:'#tb',
			pageSize: 25,
			pageList: [25,50,100],
			">
    <thead>
    <tr>
        <th data-options="field:'user_id',align:'center',width:'50px',formatter:formatUserId">用户ID</th>
        <th data-options="field:'draw_code',align:'center',width:'50px'">抽奖码</th>
        <th data-options="field:'participate_id',align:'center',width:'50px'">参与活动ID</th>
        <!--<th data-options="field:'lottery_id',align:'center',width:'50px'">中奖情况</th>-->
        <th data-options="field:'lottery_code',align:'center',width:'50px'">中奖期号</th>
        <th data-options="field:'prize_name',align:'center',width:'50px'">奖品名称</th>
        <th data-options="field:'prize_img',formatter:formatPrizeImg,align:'center',width:'50px'">奖品图片</th>
        <th data-options="field:'end_dt',align:'center',width:'50px'">获奖日期</th>
        <th data-options="field:'operation',formatter:formatOperation,align:'center',width:'50px'">操作</th>
    </tr>
    </thead>
</table>
<script type="text/javascript">
    var height = document.documentElement.clientHeight;
    height = height - 20;
    $("#dg").css("height",height+"px");
    ;!function(){
        //加载扩展模块
        layer.config({
            extend: 'extend/layer.ext.js'
        });
    }();
    function formatUserId(val) {
        return val.length == 7 ? val : "无人中奖";
    }
    function formatOperation(val,row) {
        var seqId = row.seq_id;
        var userId = row.user_id;
        return "<a href='javascript:void(0);' onclick='winningDel(\""+seqId+"\")'>删除</a>&nbsp;<a href='javascript:void(0);' onclick='winningInfo(\""+seqId+"\","+userId+")'>详情</a>";
    }
    function formatPrizeImg(val,row) {
        return "<img src=\""+val+"\" width=\"30px\" onclick=\"viewPic('"+val+"')\" style='padding: 0px 0px;margin: 0px;' alt=\""+row.prize_name+"\">";
    }
    function viewPic(url) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shadeClose: true,
            area: ['auto', 'auto'],
            content: "<img src=\""+url+"\" style='padding: 0px 0px;margin: 0px;'>"
        });
    }
    function winningInfo(seqId,userId) {
        layer.open({
            type: 2,
            title: '领奖信息',
            fix: false,
            shadeClose: true,
            maxmin: false,
            area: ['600px', '450px'],
            content: ['__URL__/winningInfo/?seq_id='+seqId+"&user_id="+userId,'no'],
            end: function(){}
        });
    }
    function winningDel(seqId) {
        layer.msg("确定删除？",{
            time: 10000, //10s后自动关闭
            btn: ['确定', '取消'],
            yes: function () {
                $.ajax({
                    url: '__URL__/winningDel',
                    type: 'post',
                    data: {'seq_id': seqId},
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        if (data > 0) {
                            layer.msg('已删除！');
                            $('#dg').datagrid({queryParams: form2Json("searchform")});
                        } else {
                            layer.msg("删除失败！");
                        }
                    },
                    error: function () {
                        layer.msg("删除异常");
                    }
                });
            }
        },{});
    }
</script>
</body>
</html>